﻿using System;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using XnaXaml.Xaml;

namespace XnaXaml.Controls
{
    public class TabItem : Control
    {
        #region Properties

        #endregion

        #region Constructor

        public TabItem() { }
        public TabItem(XNode xmlNode) : base(xmlNode) { }

        #endregion

        #region Methods

        public override void Generate(XamlRenderer renderer)
        {
            renderer.GenerateTabItem(this);
        }

        public override void Render(XamlRenderer renderer)
        {
            renderer.RenderTabItem(this);
        }

        public override void ReadAttributes()
        {
            base.ReadAttributes();

            for (var i = 0; i < Attributes.Count; i++)
            {
                var attrib = Attributes[i];
                switch (attrib.Name.LocalName)
                {
                    case "Content":
                        Content = attrib.Value;
                        break;
                    case "Margin":
                        var split = attrib.Value.Split(',');
                        var x = Convert.ToInt32(split[0]);
                        var y = Convert.ToInt32(split[1]);
                        Position = new Vector2(x, y);
                        break;
                }
            }
        }

        #endregion
    }
}
